package com.tensquare.gathering.service;

import com.tensquare.gathering.dao.GatheringDao;
import com.tensquare.gathering.pojo.Gathering;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * Created by WF on 2020/7/22 16:42
 */
@Service
public class GatheringService {
    @Autowired
    private GatheringDao gatheringDao;

    //1.根据id查询(key：直接取参数的id，值就是方法的返回值)
    @Cacheable(value="gathering",key = "#id")
    public Gathering findById(String id){
        return gatheringDao.findById(id).get();
    }
    //2.修改(先清空缓存)
    @CacheEvict(value="gathering",key="#gathering.id")
    public void update(Gathering gathering){
        gatheringDao.save(gathering);
    }
    //3.删除(先清空缓存)
    @CacheEvict(value="gathering",key="#id")
    public void delete(String id){
        gatheringDao.deleteById(id);
    }
}
